<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>moduleinfo_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_module_moduleinfo_test.js.html">moduleinfo_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.module.ModuleInfoTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.module.ModuleInfoTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.module.BaseModule&#39;);
<a name="line19"></a>goog.require(&#39;goog.module.ModuleInfo&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line21"></a>
<a name="line22"></a>
<a name="line23"></a>/**
<a name="line24"></a> * Test initial state of module info.
<a name="line25"></a> */
<a name="line26"></a>function testNotLoadedAtStart() {
<a name="line27"></a>  var m = new goog.module.ModuleInfo();
<a name="line28"></a>  assertFalse(&#39;Shouldn\&#39;t be loaded&#39;, m.isLoaded());
<a name="line29"></a>}
<a name="line30"></a>
<a name="line31"></a>var TestModule = function() {
<a name="line32"></a>  goog.module.BaseModule.call(this);
<a name="line33"></a>};
<a name="line34"></a>goog.inherits(TestModule, goog.module.BaseModule);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>/**
<a name="line38"></a> * Test loaded module info.
<a name="line39"></a> */
<a name="line40"></a>function testOnLoad() {
<a name="line41"></a>  var m = new goog.module.ModuleInfo();
<a name="line42"></a>
<a name="line43"></a>  m.setModuleConstructor(TestModule);
<a name="line44"></a>  m.onLoad(goog.nullFunction);
<a name="line45"></a>  assertTrue(m.isLoaded());
<a name="line46"></a>
<a name="line47"></a>  var module = m.getModule();
<a name="line48"></a>  assertNotNull(module);
<a name="line49"></a>  assertTrue(module instanceof TestModule);
<a name="line50"></a>
<a name="line51"></a>  m.dispose();
<a name="line52"></a>  assertTrue(m.isDisposed());
<a name="line53"></a>  assertTrue(&#39;Disposing of ModuleInfo should dispose of its module&#39;,
<a name="line54"></a>      module.isDisposed());
<a name="line55"></a>}
<a name="line56"></a>
<a name="line57"></a>
<a name="line58"></a>/**
<a name="line59"></a> * Test callbacks on module load.
<a name="line60"></a> */
<a name="line61"></a>function testCallbacks() {
<a name="line62"></a>  var m = new goog.module.ModuleInfo();
<a name="line63"></a>  m.setModuleConstructor(TestModule);
<a name="line64"></a>  var index = 0;
<a name="line65"></a>  var a = -1, b = -1, c = -1, d = -1;
<a name="line66"></a>  var ca = m.registerCallback(function() { a = index++; });
<a name="line67"></a>  var cb = m.registerCallback(function() { b = index++; });
<a name="line68"></a>  var cc = m.registerCallback(function() { c = index++; });
<a name="line69"></a>  var cd = m.registerEarlyCallback(function() { d = index++; });
<a name="line70"></a>  cb.abort();
<a name="line71"></a>  m.onLoad(goog.nullFunction);
<a name="line72"></a>
<a name="line73"></a>  assertTrue(&#39;callback A should have fired&#39;, a &gt;= 0);
<a name="line74"></a>  assertFalse(&#39;callback B should have been aborted&#39;, b &gt;= 0);
<a name="line75"></a>  assertTrue(&#39;callback C should have fired&#39;, c &gt;= 0);
<a name="line76"></a>  assertTrue(&#39;early callback d should have fired&#39;, d &gt;= 0);
<a name="line77"></a>
<a name="line78"></a>  assertEquals(&#39;ordering of callbacks was wrong&#39;, 0, d);
<a name="line79"></a>  assertEquals(&#39;ordering of callbacks was wrong&#39;, 1, a);
<a name="line80"></a>  assertEquals(&#39;ordering of callbacks was wrong&#39;, 2, c);
<a name="line81"></a>}
<a name="line82"></a>
<a name="line83"></a>
<a name="line84"></a>/**
<a name="line85"></a> * Tests the error callbacks.
<a name="line86"></a> */
<a name="line87"></a>function testErrbacks() {
<a name="line88"></a>  var m = new goog.module.ModuleInfo();
<a name="line89"></a>  m.setModuleConstructor(TestModule);
<a name="line90"></a>  var index = 0;
<a name="line91"></a>  var a = -1, b = -1, c = -1, d = -1;
<a name="line92"></a>  var ca = m.registerErrback(function() { a = index++; });
<a name="line93"></a>  var cb = m.registerErrback(function() { b = index++; });
<a name="line94"></a>  var cc = m.registerErrback(function() { c = index++; });
<a name="line95"></a>  m.onError(&#39;foo&#39;);
<a name="line96"></a>
<a name="line97"></a>  assertTrue(&#39;callback A should have fired&#39;, a &gt;= 0);
<a name="line98"></a>  assertTrue(&#39;callback B should have fired&#39;, b &gt;= 0);
<a name="line99"></a>  assertTrue(&#39;callback C should have fired&#39;, c &gt;= 0);
<a name="line100"></a>
<a name="line101"></a>  assertEquals(&#39;ordering of callbacks was wrong&#39;, 0, a);
<a name="line102"></a>  assertEquals(&#39;ordering of callbacks was wrong&#39;, 1, b);
<a name="line103"></a>  assertEquals(&#39;ordering of callbacks was wrong&#39;, 2, c);
<a name="line104"></a>}
</pre>


</body>
</html>
